package compound;

import compound.observer.Observable;
import compound.observer.Observer;

import java.util.ArrayList;
import java.util.Iterator;

public class Flock implements QuackAble {
    ArrayList<QuackAble> quackAbles = new ArrayList<>();
    Observable observable;

    public void add(QuackAble quackAble) {
        quackAbles.add(quackAble);
        observable = new Observable(this);
    }

    @Override
    public void quack() {
        Iterator<QuackAble> iterator = quackAbles.iterator();
        while (iterator.hasNext()) {
            QuackAble next = iterator.next();
            next.quack();
        }
    }

    @Override
    public void registerObserver(Observer observer) {
        observable.registerObserver(observer);
    }

    @Override
    public void notifyObservers() {
        observable.notifyObservers();
    }
}
